<?php

namespace UC_PHP\FileSystem;

if (!defined('UC_FILESYSTEM_ROOT')) 
{
    define('UC_FILESYSTEM_ROOT', dirname(__FILE__));
}

class Autoloader
{
    public static function Register()
    {
        if (function_exists('__autoload')) 
        {
            spl_autoload_register('__autoload');
        }
        
        return spl_autoload_register(array('UC_PHP\\FileSystem\\Autoloader', 'Load'));
    }
    
    public static function Load($class_name)
    {
        if(strpos($class_name, 'UC_PHP') === FALSE)
        {
            return FALSE;
        }
        
        $file_name_array = explode('\\', $class_name);
        $file_name = $file_name_array[count($file_name_array) - 1];

        if ((class_exists($file_name))) 
        {
            return FALSE;
        }

        $class_file_path = UC_FILESYSTEM_ROOT . 
            DIRECTORY_SEPARATOR . $file_name . '.php';

        if (!file_exists($class_file_path) || !is_readable($class_file_path)) 
        {
            return FALSE;
        }

        require_once $class_file_path;
    }
}

